package file;

import java.io.File;
import java.io.FileFilter;

/**
 * 说明:
 *
 * @author:SuZhongHe
 * @date:2023/3/6
 **/
public class ListFilesDemo2 {
    public static void main(String[] args) {
        File file = new File(".");
        if(file.isDirectory()){
            FileFilter filter = new FileFilter() {
                @Override
                public boolean accept(File file1) {
                    String name = file1.getName();
                    return name.endsWith(".txt");
                }
            };
            File[] files = file.listFiles(filter);
            for (File file1 : files) {
                System.out.println(file1.getName());
            }
        }
    }
}
